package com.ruoyi.starbucks.service;

import com.ruoyi.common.utils.http.HttpUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.MessageFormat;


public class SrmService {

    public static String userName = "15995815769";

    public static String password = "abc880918";

    public static String projectName = "星巴克";

    public static String GetPhoneNo() {
        try {
            projectName = URLEncoder.encode("星巴克","UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String url = MessageFormat.format("http://api.xunyaosoft.com/zc/zhicode/api.php?code=getPhoneNo&projName={0}&uPhoneNo={1}&uPassword={2}",projectName,userName,password);
        String data = HttpUtils.sendGet(url,null);
        if (data.contains("密码错误或登录过期"))
        {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            HttpUtils.sendGet(MessageFormat.format("http://api.xunyaosoft.com/zc/zhicode/api.php?code=signIn&uPhoneNo={0}&uPassword={1}",userName,password),null);
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            data = HttpUtils.sendGet(url,null);
        }
        return data;
    }

    public static String GetMessage(String phoneNo) {
        try {
            projectName = URLEncoder.encode("星巴克","UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String url = MessageFormat.format("http://api.xunyaosoft.com/zc/zhicode/api.php?code=getMsg&uPhoneNo={0}&uPassword={1}&projName={2}&phoneNo={3}",userName,password,projectName,phoneNo);
        String data = HttpUtils.sendGet(url,null);
        return data;
    }

    public static String AddToBlackList(String phoneNo){
        String url =MessageFormat.format("http://api.xunyaosoft.com/zc/zhicode/api.php?code=block&uPhoneNo={0}&uPassword={1}&phoneNo={2}",userName,password,phoneNo);
        String data =   HttpUtils.sendGet(url,null);
        return data;
    }
}
